import grails.util.Environment
import soccer.stats.Team
import soccer.stats.Person
import soccer.stats.PlayerHistory

class BootStrap {
    def init = { servletContext ->
        if(Environment.current == Environment.DEVELOPMENT) testData()
    }

    def destroy = {
        
    }

    private def testData = {
        // Populate a few teams
        if(!Team.count()) {
            new Team(name: "Chelsea", country: "England", teamType: "club").save(failOnError: true)
        }

        // Populate a few players
        if(!Person.count()) {
            new Person(name: "Fernando Torres", birthPlace: "Madrid, Spain").save(failOnError: true)
        }

        // Populate a few player histories
        if(!PlayerHistory.count()) {
            new PlayerHistory(player: Person.findByName("Fernando Torres"), team: Team.findByName("Chelsea"), currentTeam: true, mainPosition: "striker", personRole: "player", squadNumber: 9).save(failOnError: true)
        }
    }
}
